package com.example.springboot.service;

import com.example.springboot.entity.Applications;
import com.example.springboot.mapper.ApplicationsMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ApplicationsService {

    @Autowired
    private ApplicationsMapper applicationsMapper;

    public List<Applications> findAllApplications() {
        return applicationsMapper.findAll();
    }

    public Applications findApplicationById(int id) {
        return applicationsMapper.findById(id);
    }

    public List<Applications> findapplicationsByStudentId(String studentId) {
        return applicationsMapper.findByStudentId(studentId);
    }

    public void saveApplication(Applications application) {
        if (application.getApplication_id() == 0) {
            applicationsMapper.insert(application);
        } else {
            applicationsMapper.update(application);
        }
    }

    public void deleteApplication(int id) {
        applicationsMapper.delete(id);
    }

    public void registerForTest(int id) {
        applicationsMapper.updateStatus(id, "interviewed");
    }
    public List<Applications> getAllApplications(){
        return  applicationsMapper.getAllApplications();
    }


    public void applyInsert(Applications application){
        applicationsMapper.applyInsert(application);
    }

    public void saveApplicationN(int applicationId, String applicationStatus) {
        applicationsMapper.saveApplicationN(applicationId,applicationStatus);
    }
}